package com.gk.init.control
{
	import com.gk.app.CommandList;
	import com.gk.company.control.event.UpdateFriendListInfoEvent;
	import com.gk.company.control.event.UpdateUserInfoEvent;
	import com.gk.company.view.event.GoMyCompanyEvent;
	import com.gk.init.model.UserInfoModel;
	import com.gk.init.model.vo.UserInfoVo;
	import com.gk.util.net.RemoteExecuter;
	
	import org.robotlegs.mvcs.Command;

	/**
	 *初始化用户数据命令 
	 * @author Nestor
	 * 
	 */	
	public class InitUserDataCommand extends Command
	{
		
		[Inject]
		public var userInfoModel:UserInfoModel;
		
		public function InitUserDataCommand()
		{
			super();
		}
		
		override public function execute():void
		{
			// TODO Auto Generated method stub
			super.execute();
			
			var obj:Object = {"command":CommandList.INIT_USER_DATA,"userId":userInfoModel.userInfo.user_id};
			new RemoteExecuter(obj,result);
		}
		
		private function result(obj:Object):void
		{
/*<<{"friends":[{"userPic":"http://hdn.xnimg.cn/photos/hdn411/20090710/1030/head_LR6Y_7531i204235.jpg","userId":"3","userSex":"男","userName":"杜海涛"},
{"userPic":"http://hd11.xiaonei.com/photos/hd11/20071020/21/12/head_954g170.jpg","userId":"2","userSex":"男","userName":"孙后继"}],
"userInfo":[{"userPic":"http://head.xiaonei.com/photos/0/0/men_head.gif","userId":"4","userSex":"男","userName":"王斯樵"}]}*/

			//用户个人信息
			userInfoModel.userInfo.user_id = obj.userInfo[0].userId;
			userInfoModel.userInfo.user_name = obj.userInfo[0].userName;
			userInfoModel.userInfo.user_pic = obj.userInfo[0].userPic;
			userInfoModel.userInfo.user_sex = obj.userInfo[0].userSex;
			
			
			userInfoModel.userInfo.kbNum = Math.random() * 10000;
			userInfoModel.userInfo.mbNum = Math.random() * 10000;
			userInfoModel.userInfo.popularNum = Math.random() * 10000;
			

			//用户好友信息
			var friendVect:Vector.<UserInfoVo> = new Vector.<UserInfoVo>();
			for each( var o:Object in obj.friends){
				var userVo:UserInfoVo = new UserInfoVo();
				userVo.user_id = o.userId;
				userVo.user_name = o.userName;
				userVo.user_pic = o.userPic;
				userVo.user_sex = o.userSex;
				
				userVo.kbNum = Math.random() * 10000;
				userVo.mbNum = Math.random() * 10000;
				userVo.popularNum = Math.random() * 10000;
				
				friendVect.push(userVo);
			}
			userInfoModel.friendInfo = friendVect;
			
			dispatch(new GoMyCompanyEvent(GoMyCompanyEvent.GO_MY_COMPANY,userInfoModel.userInfo));
			dispatch(new UpdateFriendListInfoEvent(UpdateFriendListInfoEvent.UPDATE_FRIEND_LIST,userInfoModel.friendInfo));
		}
		
	}
}